package com.happyass.service.impl;

import com.happyass.dao.EvaluateDao;

import com.happyass.dao.StaffDao;
import com.happyass.dao.UserDao;
import com.happyass.pojo.Evaluate;
import com.happyass.pojo.Staff;
import com.happyass.pojo.User;
import com.happyass.pojo.page.PageInfo;
import com.happyass.service.EvaluateService;
import com.happyass.show.entity.Activity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class EvaluateServiceImpl implements EvaluateService {
    @Autowired
    private EvaluateDao evaluateDao;
    @Autowired
    private StaffDao staffDao;

    @Override
    public List<Evaluate> selectAll() {
        return evaluateDao.findAll();
    }

    @Override
    public Boolean editStatus(Integer evaluateId,Integer evaluateStatus) {
        Evaluate evaluate = evaluateDao.findById(evaluateId).get();
            if (evaluate.getEvaluateStatus()!=evaluateStatus) {
                evaluate.setEvaluateStatus(evaluateStatus);
                evaluateDao.save(evaluate);
                return true;
            } else {
                return false;
            }

    }

    @Override
    public List<Evaluate> selectByStaus() {
        return evaluateDao.selectByStaus();
    }

    @Override
    public double averageStar() {
        return evaluateDao.averageStar();
    }

    @Override
    public List<Evaluate> findByEvaluateStar(Integer evaluateStar) {
        return evaluateDao.findByEvaluateStar(evaluateStar);
    }

    @Override
    public Page<Evaluate> selectAllevaluate(Integer page, Integer row) {
        Pageable pageable = PageRequest.of(page - 1, row);
        return evaluateDao.findAll(pageable);
    }
@Autowired
    UserDao userDao;
    @Override
    public HashMap<String, Object> insertEvaluate(String staffUsername, String evaluateTime, String evaluateContent, Integer evaluateStar) {
        HashMap<String, Object> map = new HashMap<>();
        Evaluate evaluate = new Evaluate();
            evaluate.setEvaluateStar(evaluateStar);
            evaluate.setEvaluateContent(evaluateContent);
            evaluate.setEvaluateTime(evaluateTime);
        Staff staff = staffDao.findByStaffUsername(staffUsername);
        User user = new User();
        user.setUserId(1);
        userDao.save(user);
        staff.setStaffUsername(staffUsername);
        evaluate.setEvaluateStatus(1);
        staffDao.save(staff);
            evaluateDao.save(evaluate);
            map.put("info","评价成功，谢谢！");
            return map;
    }

}
